<?php
namespace App\Services\Admin;

use Illuminate\Support\Facades\DB;

class UserService extends BaseService
{
    /**
     * 服务
     */

    /**
     * 获取列表
     * @param array $pages【start起始页，limit每页记录数】
     * return array
     */
    public function getIndex($pages)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $total = $this->dbConn($this->dbUser)->count();
        $res = $this->dbConn($this->dbUser)
            ->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $arys[] = [
                'id' => $v['id'],
                'uname' => $v['nickName'],
                'uhead' => $v['avatarUrl'],
                'addtime' => $v['addtime'],
                'uptime' => $v['uptime'],
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }

    /**
     * 获取列表
     * @param array $pages【start起始页，limit每页记录数】
     * return array
     */
    public function getVisitorIndex($pages)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $res = $this->dbConn($this->dbUser)
            ->where('phone', '')
            ->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        return $this->toback(0, '', $res);
    }
}